package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.FamilyMemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataByDayVo;
import com.zzyl.nursing.vo.FamilyVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IDeviceService deviceService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 绑定老人
     * @param familyMemberElderDto 老人信息
     * @return AjaxResult
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FamilyMemberElderDto familyMemberElderDto) {
        familyMemberService.insertFamilyMemberElder(familyMemberElderDto);
        return success();
    }
    @GetMapping("/my")
    public AjaxResult my() {
        return success(familyMemberService.my());
    }
    /**
     * 查询我的老人列表
     * @return
     */
    @GetMapping("/list-by-page")
    public AjaxResult page() {
        startPage();
        List<FamilyVo> list = familyMemberService.selectFamilyMemberElder();
        return success(list);
    }
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        return  deviceService.queryDevicePropertyStatus(request);
    }
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(@RequestParam("iotId") String iotId,
                                               @RequestParam("startTime") Long startTime,
                                               @RequestParam("endTime") Long endTime,
                                               @RequestParam("functionId") String functionId) {
        List<DeviceDataByDayVo> list = deviceService.queryDeviceDataListByDay(iotId, startTime, endTime, functionId);
        return success(list);
    }
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(@RequestParam("iotId") String iotId,
                                                @RequestParam("startTime") Long startTime,
                                                @RequestParam("endTime") Long endTime,
                                                @RequestParam("functionId") String functionId) {

        List<DeviceDataByDayVo> list = deviceService.queryDeviceDataListByWeek(iotId, startTime, endTime, functionId);
        return success(list);
    }
    @GetMapping("/pageQueryAlertData")
    public AjaxResult pageQueryAlertData(@RequestParam("iotId") String iotId,
                                         @RequestParam("startTime") Long startTime,
                                         @RequestParam("endTime") Long endTime,
                                         @RequestParam("functionId") String functionId
    ) {
        startPage();
        List<DeviceData> list = deviceService.selectData(iotId, startTime, endTime,functionId);
        return success(list);
    }


}
